Skip to main content

Compare with IBP

Now that our forecasting is complete, we can compare the forecasts with IBP and get the difference in accuracy and errors.

compare is a function that takes forecast data, IBP forecasts and the brand name as parameters and returns the r2 score, IBP r2 score and absolute errors of both from the actual.

ibp = pd.read_csv(f"data/{country}/IBP.csv")

"""
data is dataframe of our forecasts and actual for each brand
clean_ibp is a function to aggregate forecasts for all SKUs of each brand and merge with data
"""

df = clean_ibp(data, ibp)

comparison, actual = {}, {}

for brand in df.brand.unique():
comparison[brand] = {}
r2, ibp_r2, df = compare(df, brand)
comparison[brand]["Ours"], comparison[brand]["IBP"] = r2, ibp_r2
actual[brand] = df

comparison = pd.DataFrame(comparison).transpose()
comparison["Improvement"] = comparison["Ours"] - comparison["IBP"]
comparison = comparison.reset_index(names="brand")

final = pd.DataFrame()
for brand in actual.keys():
final = pd.concat([final, actual[brand]])
final["Improvement"] = final["IBP error"] - final["my error"]

final[["Forecast", "IBP", "Actual", "my error", "IBP error", "Improvement"]] /= 1000

This whole process from updating the actual data and IBP forecasts to forecasting and comparing with IBP is encapsulated in a library. However, this library is specific to this project and therefore was not published for public use.